<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use app\admin\model\Goods as GoodsModel;

/**
 * 首页接口
 */
class UserContacts extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    /**
     * 商品列表
     *
     */
    public function list()
    {
        // $page = $this->request->post("page",1);
        // $pageSize = $this->request->post("pageSize",10);
        // $area = $this->request->post("area");
        // $sort = $this->request->post("sort",'weigh');
        // $order = $this->request->post("order",'desc');
        // $where = [
        //     'city'   => ['like','%'.$area.'%'],
        //     'status' => 3,
        // ];
        $a = $this->auth->getUser();
        $b = $this->auth->getUserinfo();
        dump([$a,$b]);die;
        $goodsList = GoodsModel::with('group')
            ->where($where)
            ->order($sort, $order)
            ->page($page, $pageSize)
            ->select();
        $this->success('返回成功', $goodsList);
    }


    /**
     * 商品详情
     *
     */
    public function detail()
    {
        $id = $this->request->post("id");
        $where = [
            // 'flag'=> ['like','%index%'],
            'status' => 3,
        ];
        $goods = GoodsModel::with('group')
            ->where($where)
            ->find($id);
        $orderCount = db('order')
            ->where([
                'goods_id' => $id,
                'status'   => 4,
            ])
            ->count();
        $this->success('返回成功', ['goods' => $goods,'orderCount' => $orderCount]);
    }

}
